/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tencent.tendon.convert.jsontest.record;

import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField;
import com.tencent.tendon.convert.json.JsonFactory;
import com.tencent.tendon.convert.jsontest.Performance;
import com.tencent.tendon.convert.jsontest.Utility;
import com.tencent.tendon.convert.util.Creator;
import com.tencent.tendon.convert.util.CreatorFields;

/**
 *
 * @author nbzhang
 */
public class NoEmptyConstructRecord {

    private int id;

    private String name;

    private long qq;

    private int age;

    @JSONCreator
    public NoEmptyConstructRecord(@JSONField(name = "id") int id, @JSONField(name = "name") String name) {
        this.id = id;
        this.name = name;
    }

    public static void main(String[] args) throws Throwable {

        JsonFactory.register(NoEmptyConstructRecord.class, new Creator<NoEmptyConstructRecord>() {

            @CreatorFields({"id", "name"})
            public NoEmptyConstructRecord create(Object... params) {
                return new NoEmptyConstructRecord((params[0] == null ? 0 : (Integer) params[0]), (String) params[1]);
            }
        });

        NoEmptyConstructRecord record = new NoEmptyConstructRecord(9, "haha");
        record.setAge(18);
        Performance.run(record);
        //System.out.println(JsonConvert.convertFrom("{name : 'haha', age : 18}", NoEmptyConstructRecord.class));
    }

    @Override
    public String toString() {
        return Utility.listingString(this);
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getQq() {
        return qq;
    }

    public void setQq(long qq) {
        this.qq = qq;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
